package com.bristua.user.biz;

import com.bristua.common.bean.PageBean;
import com.bristua.user.dao.TUserCashFlowMapper;
import com.bristua.user.model.TUserCashFlow;
import com.bristua.user.model.condition.QueryUserCashFlowParams;
import com.bristua.user.model.condition.TUserCashFlowExample;
import com.bristua.user.model.vo.QueryUserCashFlowVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/4/3.
 */
@Service
public class QueryUserCashFlowBiz {

    @Resource
    private TUserCashFlowMapper tUserCashFlowMapper;

    public PageBean queryUserCashFlow(QueryUserCashFlowParams queryUserCashFlowParams){

        TUserCashFlowExample tUserCashFlowExample = new TUserCashFlowExample();
        TUserCashFlowExample.Criteria criteria = tUserCashFlowExample.createCriteria();

        if(!StringUtils.isEmpty(queryUserCashFlowParams.getStartTime())){
            criteria.andCreateTimeGreaterThan(queryUserCashFlowParams.getStartTime()+" 00:00:00");
        }

        if(!StringUtils.isEmpty(queryUserCashFlowParams.getEndTime())){
            criteria.andCreateTimeLessThan(queryUserCashFlowParams.getEndTime()+" 23:59:59");
        }
        Page<TUserCashFlow> objects = PageHelper.startPage(queryUserCashFlowParams.getPageNo(),queryUserCashFlowParams.getPageSize());
        tUserCashFlowMapper.selectByExample(tUserCashFlowExample);
        PageBean data = new PageBean<>(objects);
        if(data.getList()!=null && data.getList().size()>0){
            List<QueryUserCashFlowVO> queryUserCashFlowVOS = new ArrayList<>();
            for(int i=0;i<data.getList().size();i++){
                TUserCashFlow tUserCashFlow = (TUserCashFlow) data.getList().get(i);
                QueryUserCashFlowVO queryUserCashFlowVO = new QueryUserCashFlowVO();
                BeanUtils.copyProperties(tUserCashFlow,queryUserCashFlowVO);
                queryUserCashFlowVOS.add(queryUserCashFlowVO);
//                tDevice.setIsOnline(DeviceCode.getValueByCode(Integer.valueOf(tDevice.getIsOnline())));
            }
            data.getList().clear();
            data.getList().addAll(queryUserCashFlowVOS);
        }
        return data;
    }
}
